package Solution.problem073;

import java.util.HashSet;
import java.util.Set;

/**
 * @program Leetcode
 * @description:
 * @author: lishangsheng
 * @create: 2019/06/11 09:36
 */
public class Solution {
    public static void setZeroes(int[][] matrix) {
        if(matrix.length==0||matrix[0].length==0){
            return;
        }
        int row=matrix.length;
        int col=matrix[0].length;
        Set<Integer> rows=new HashSet<>();
        Set<Integer>  cols=new HashSet<>();
        for(int i=0;i<row;i++){
            for (int j=0;j<col;j++){
                if(matrix[i][j]==0) {
                    rows.add(i);
                    cols.add(j);
                }
            }
        }
        rows.parallelStream().forEach(x->{
            for(int j=0;j<col;j++){
                if(matrix[x][j]!=0){
                    matrix[x][j]=0;
                }
            }
        });

        cols.parallelStream().forEach(x->{
            for(int i=0;i<row;i++){
                if(matrix[i][x]!=0){
                    matrix[i][x]=0;
                }
            }
        });

    }

    public static void main(String[] args){

        //[[0,1,2,0],[3,4,5,2],[1,3,1,5]]
        int[][] array=new int[][]{{0,1,2,0},{3,4,5,2},{1,3,1,5}};
        setZeroes(array);
        System.out.println(array);
    }
}
